function C=jacobiConst(y,v,mu)

%File computes Jacobi Energy for a given state (x,v)




%the distances
r1=sqrt((mu+y(1))^2+(y(2))^2+(y(3))^2);
r2=sqrt((y(1)-(1-mu))^2+(y(2))^2+(y(3))^2);

U = 1/2 * (y(1)^2+y(2)^2) + (1-mu)/r1 + mu/r2;
V2 = v(1)^2 + v(2)^2 + v(3)^2;

% C = 2 * U + V2;
C = 1/2 * (v(1).^2+v(2).^2+v(3).^2) - 1/2*(y(1).^2+y(2).^2+y(3).^2) - (1-mu)./r1 - mu./r2;
C = 2*abs(C);
%Compute the Jacobi Energy
% C=-(v(1,1)^2 + v(2,1)^2+v(3,1)^2)/2 + 2*((y(1,1)^2 + y(2,1)^2 + y(3,1)^2)/2 + (1-mu)/r1 + mu/r2);

